package com.xianan.xuhui.netsecurityproject.interceptor;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author xiaoli
 * @description mvc拦截器配置类
 * @since 2025/3/25 1:28
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
public class WebInterceptorsConfig implements WebMvcConfigurer {
    private final WebBindPhoneInterceptor webBindPhoneInterceptor;
    private final WebTokenAuthInterceptor webTokenAuthInterceptor;
    private final CorsInterceptor corsInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("应用请求WebMvc拦截器注册开始......");
        // 跨域拦截器生效
        registry.addInterceptor(corsInterceptor)
                .addPathPatterns("/**");

        registry.addInterceptor(webTokenAuthInterceptor)
                .addPathPatterns("/api/web/**")
                .excludePathPatterns("/api/web/login/login")
                .excludePathPatterns("/api/web/login/logout")
                .excludePathPatterns("/api/web/login/logtest")
                .excludePathPatterns("/api/web/task/mbtiNoSessionTask")
                .excludePathPatterns("/api/web/task/mbtiNoSessionSubmit")
                .excludePathPatterns("/api/web/public/**");

        registry.addInterceptor(webBindPhoneInterceptor)
                .addPathPatterns("/api/web/**")
                .excludePathPatterns("/api/web/login/login")
                .excludePathPatterns("/api/web/login/logout")
                .excludePathPatterns("/api/web/login/logtest")
                .excludePathPatterns("/api/web/task/mbtiNoSessionTask")
                .excludePathPatterns("/api/web/task/mbtiNoSessionSubmit")
                .excludePathPatterns("/api/web/public/**")
                .excludePathPatterns("/api/web/employee/**");//修改员工相关信息不要求必须绑定手机号
        log.info("应用请求Web拦截器注册结束......");
    }

}
